package com.alks.function.controller.subcontract;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.stringUtils.ZStringUtils;
import com.alks.entity.data.entity.dispatch.OemLotHead;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.service.subcontract.SubcontractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author:hxl
 * @create: 2024-07-25 10:02
 * @Description:
 */
@ApiRestController("/subcontract/static")
@Api(tags = "量产订单")
public class SubcontractStaticController {
    @Autowired
    private SubcontractService subcontractService;

    @ApiOperation(value = "订单列表",tags = "量产订单")
    @PostMapping("/list")
    @WebLogger
    public ResponseInfo list(OemLotHead oemLotHead){
        return subcontractService.searchOemLotHead(oemLotHead);
    }

    //结案
    @ApiOperation(value = "结案",tags = "量产订单")
    @PostMapping("/complete")
    @WebLogger
    public ResponseInfo complete(@RequestBody OemLotHead oemLotHead){
        return subcontractService.complete(oemLotHead);
    }
    //取消结案
    @ApiOperation(value = "取消结案",tags = "量产订单")
    @PostMapping({"/cancel/complete"})
    @WebLogger
    public ResponseInfo cancelComplete(@RequestBody OemLotHead oemLotHead){
        return subcontractService.cancelComplete(oemLotHead);
    }

    @ApiOperation(value = "订单修改",tags = "量产订单")
    @PostMapping({"/updatePrice"})
    @WebLogger
    public ResponseInfo updatePrice(@RequestBody OemLotHead oemLotHead){
        return subcontractService.updatePrice(oemLotHead);
    }

    @ApiOperation(value = "订单删除",tags = "量产订单")
    @PostMapping({"/delete"})
    @WebLogger
    public ResponseInfo delete(@RequestBody OemLotHead oemLotHead) {
        if (ZStringUtils.isNull(oemLotHead.getUuid())) return ResponseInfo.error("uuid不能为空");
        return subcontractService.delete(oemLotHead);
    }

    @ApiOperation(value = "订单删除",tags = "量产订单")
    @PostMapping({"/deleteList"})
    @WebLogger
    public ResponseInfo deleteList(@RequestBody List<OemLotHead> oemLotHead) {
        return subcontractService.deleteList(oemLotHead);
    }

    @PostMapping({"/oem/combo"})
    @ApiOperation(value = "oem下拉框",tags = "量产订单")
    @WebLogger
    public ResponseInfo oemCombo(String searchKey){
        List<String> vendorTypes = new ArrayList<>();
        vendorTypes.add("G17");
        return subcontractService.oemCombo(searchKey,vendorTypes);
    }

    @PostMapping({"/download/oem"})
    @ApiOperation(value = "导出oem",tags = "量产订单")
    @WebLogger
    public void downloadOem(OemLotHead oemLotHead, HttpServletResponse response) throws IOException {
        subcontractService.downloadOem(oemLotHead,response);
    }
    //根据款号导出汇总表

//    @PostMapping({"/download/excel/downloadExcelPlan"})
//    @WebLogger
//    @ApiOperation(value = "根据款号导出excel",tags = "量产订单")
//    public void downloadExcelPlan(@RequestParam String styleNo , HttpServletResponse response) throws IOException {
//        String fileName = "批量导入模板.xlsx";
//        //获取文件下载路径
//        String filePath = "/templates/template.xlsx";
//        TemplateDownloadUtil.download(response, fileName, filePath);
//    }

}
